/*
 * @Author: wangc
 * @Date: 2021-03-04 16:24:41
 * @Description: 用户权限
 */

import Vue from 'vue'
import { getInfo } from "@/utils/auth"

function havePermissions(functionCode) {
    // 用户权限按钮
    const functionLists = getInfo().roles.split(',')
    if (functionLists === undefined || functionLists === null) {
        return false;
    }
    if (Array.isArray(functionLists) && functionLists.length) {
        return functionLists.some(x => functionCode.includes(x))
    }
    return true
}

Vue.directive('permissions', {
    bind(el, { value }) {
        if (!havePermissions(value)) {
            if (el.parentNode) {
                el.parentNode.removeChild(el)
            } else {
                el.style.display = 'none'
            }
        }
    }
})

Vue.prototype.$returnPermissions = havePermissions